#include "oncrpc-wrapper.h"

#include <stdarg.h>

SVCXPRT * wnfs_svcudp_create(int sock)
{
  return svcudp_create(sock);
}

SVCXPRT * wnfs_svctcp_create(int sock, u_int sendsize, u_int recvsize)
{
  return svctcp_create(sock, sendsize, recvsize);
}

bool_t wnfs_svc_register(SVCXPRT *xprt, u_long prog, u_long vers, void (*dispatch)(struct svc_req *, SVCXPRT *), int protocol)
{
  return svc_register(xprt, prog, vers, dispatch, protocol);
}

bool_t wnfs_svc_sendreply(SVCXPRT *xprt, ... /*xdrproc_t xdr_results, caddr_t xdr_location*/)
{
  xdrproc_t xdr_results;
  caddr_t xdr_location;
  bool_t res;

  va_list args;
  va_start(args, xprt);
  xdr_results = va_arg(args, xdrproc_t);
  xdr_location = va_arg(args, caddr_t);
  res = svc_sendreply(xprt, xdr_results, xdr_location);
  va_end(args);

  return res;
}

bool_t wnfs_svc_getargs(SVCXPRT *xprt, ...)
{
  typedef bool_t(*func)();
  func xargs;
  void *argsp;
  bool_t res = FALSE;

  va_list args;
  va_start(args, xprt);
  xargs = va_arg(args, func);
  argsp = va_arg(args, void*);
  res = svc_getargs(xprt, xargs, argsp);
  va_end(args);

  return res;
}

bool_t wnfs_xdr_u_long(XDR *xdrs, u_long *ulp)
{
  return xdr_u_long(xdrs, ulp);
}

bool_t wnfs_xdr_opaque(XDR *xdrs, caddr_t cp, u_int cnt)
{
  return xdr_opaque(xdrs, cp, cnt);
}

bool_t wnfs_xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize)
{
  return xdr_bytes(xdrs, cpp, sizep, maxsize);
}

bool_t wnfs_xdr_u_char(XDR *xdrs, char *cp)
{
  return xdr_u_char(xdrs, cp);
}

bool_t wnfs_xdr_int(XDR *xdrs, int *ip)
{
  return xdr_int(xdrs, ip);
}

bool_t wnfs_xdr_bool(XDR *xdrs, bool_t *bp)
{
  return xdr_bool(xdrs, bp);
}
